(function() {
  'use strict';

  define(['app', 'services/ListService'], function(AMail) {
    AMail.controller('ListController', ['$scope', 'ListService', '$location', function($scope, ListService, $location) {
      $scope.reload = function() {
        ListService.reload(function() {
          $scope.messages = this.messages;
        });
      };

      $scope.remove = ListService.remove;
      $scope.newMessage = ListService.newMessage;
      $scope.removeAll = ListService.removeAll;
      $scope.removeSelected = function() {
        $scope.remove($scope.selected);
      };

      $scope.setSelected = function(index) {
        $scope.selected = index;
      };

      $scope.backtolist = function() {
        // go to index.html
        $location.path('');
      };

      $scope.reload();
    }]);
  });
}).call(this);